package com.innovation.chengzhangriji.ui.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.ViewOutlineProvider;
import android.widget.Button;

import com.innovation.chengzhangriji.ChZhRJApplication;
import com.innovation.chengzhangriji.R;
import com.innovation.chengzhangriji.ui.graphics.SelectorDrawable;

public class CuteButton extends Button {

    public CuteButton(Context context) {
        super(context);
        init(context, null);
    }

    public CuteButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public CuteButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    public void setCuteBackgroundDrawable(Drawable drawable) {
        setBackgroundDrawable(new SelectorDrawable(drawable));
    }

    private void init(Context context, AttributeSet attrs) {
        setTypeface(((ChZhRJApplication) context.getApplicationContext()).getTypeface());
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CuteButton);
        Drawable cuteBackground = typedArray.getDrawable(R.styleable.CuteButton_cute_background);
        typedArray.recycle();
        if (cuteBackground != null) {
            setBackgroundDrawable(new SelectorDrawable(cuteBackground));
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setOutlineProvider(null);
        }
    }

}
